// 命令模式
let bindClick = function(btn,func){
  btn.onClick = func
}
let MenuBar = {
  refresh: function(){
    console.log('MenuBar refresh')
  }
}
let SubMenu = {
  add: function(){
    console.log('SubMenu add')
  },
  del: function(){
    console.log('SubMenu del')
  }
}

bindClick(button1,MenuBar.refresh)
bindClick(button2,SubMenu.add)
bindClick(button3,SubMenu.del)

// 闭包
let setCommand = function(btn,func){
  btn.onClick = function(){
    // 执行之前
    func()
    // 执行之后
  }
}

let MenuBar = {
  refresh: function(){
    console.log('MenuBar refresh')
  }
}

let RefeshMenuBarCommand = function(receiver){
  return function(){
    receiver.refresh()
  }
}


let refeshMenuBarCommand = new RefeshMenuBarCommand(MenuBar)
setCommand(botton1,refeshMenuBarCommand)

// Macro
let closeDoorCommand = {
  execute: function(){
    console.log('关门')
  }
}

let openCpmputerCommand = {
  execute: function(){
    console.log('开电脑')
  }
}

let openWXCommand = {
  execute: function(){
    console.log('打开微信')
  }
}

let MacroCommand = function(){
  return {
    commandList: []
    add: function(command){
      this.commandList.push(command)
    },
    execute: function(){
      for(let i = 0;i<this.commandList.length;i++){
        const command = this.commandList[i]
        command.execute()
      }
    }
  }
}

let macro = new MacroCommand()

macro.add(closeDoorCommand)
macro.add(openCpmputerCommand)
macro.add(openWXCommand)
macro.execute()


let obj ={

}